﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace StockMatch.WebSite.Mvc
{
    public static class AreaRegistrationContextExtensions
    {
        public static DomainRoute MapDomainRoute(this AreaRegistrationContext context, string name)
        {
            return context.MapDomainRoute(name, null);
        }
        public static DomainRoute MapDomainRoute(this AreaRegistrationContext context, string name, object defaults)
        {
            return context.MapDomainRoute(name, defaults, null);
        }
        public static DomainRoute MapDomainRoute(this AreaRegistrationContext context, string name, string[] namespaces)
        {
            return context.MapDomainRoute(name, null, namespaces);
        }


        #region

        public static DomainRoute MapDomainRoute(this AreaRegistrationContext context, string name,
            object defaults, string[] namespaces)
        {
            DomainRouteSection mainSite = DomainConfig.GetDomainRouteConfig(name);
            return context.MapDomainRoute(name, mainSite.domain, mainSite.url, defaults, null, namespaces);
        }
        public static DomainRoute MapDomainRoute(this AreaRegistrationContext context, string name,
            object defaults, object constraints)
        {
            DomainRouteSection mainSite = DomainConfig.GetDomainRouteConfig(name);
            return context.MapDomainRoute(name, mainSite.domain, mainSite.url, defaults, constraints, null);
        }

        #endregion

        public static DomainRoute MapDomainRoute(this AreaRegistrationContext context, string name, string domain,
            string url, object defaults, object constraints, string[] namespaces)
        {
            if ((namespaces == null) && (context.Namespaces != null))
            {
                namespaces = context.Namespaces.ToArray<string>();
            }
            DomainRoute route = context.Routes.MapDomainRoute(name, domain, url, defaults, constraints, namespaces);
            route.DataTokens["area"] = context.AreaName;
            bool flag = (namespaces == null) || (namespaces.Length == 0);
            route.DataTokens["UseNamespaceFallback"] = flag;
            return route;
        }
    }
}
